﻿namespace CV.Web.Tools
{
    using System;
    using System.Linq.Expressions;
    using System.Web.Mvc;
    using System.Web.Mvc.Html;

    public static class HtmlExtentions
    {
        //  <div class="input-group date">
        //      <input type="text" class="form-control">
        //      <span class="input-group-addon">
        //          <i class="glyphicon glyphicon-th"></i>
        //      </span>
        //  </div>
        public static MvcHtmlString DatePickerFor<TModel, TProperty>(this HtmlHelper<TModel> htmlHelper, Expression<Func<TModel, TProperty>> expression, object htmlAttributes)
        {
            var i = TagBuilderFactory.CreateTagBuilder("i", "glyphicon", "glyphicon-th");
            var span = TagBuilderFactory.CreateTagBuilder("span", "input-group-addon");
            var div = TagBuilderFactory.CreateTagBuilder("div", "input-group", "date");

            span.InnerHtml = i.ToString(TagRenderMode.Normal);

            div.InnerHtml = String.Concat(
                htmlHelper.TextBoxFor(expression, htmlAttributes).ToString(),
                span.ToString(TagRenderMode.Normal)
            );

            return MvcHtmlString.Create(div.ToString(TagRenderMode.Normal));

        }
    }
}
